<?php 
/**
 *  【梦想cms】 http://www.lmxcms.com
 * 
 *   前台栏目页面控制器
 */
defined('LMXCMS') or exit();
use \GatewayWorker\Lib\Gateway;
class GameAction extends HomeAction{
    private $SocketData;
    protected $DataModel;

    public function __construct(){
        parent::__construct();
        global $SocketData;
        $this->SocketData=$SocketData;
        if($this->DataModel==null){
            $this->DataModel=new DataModel();
        }
    }

    //用户从列表页面进入游戏房间  判断游戏状态  返回初始化数据给客户端
    public function index(){

    }

    //用户的投币方法 接收用户的投币数据  返回用户当前所属状态和
    public function play(){
        $uid=$this->SocketData['uid'];
        $roomid=$this->SocketData['roomid'];
        $OnUserArray=$this->DataModel->getOnUserData();

        if(in_array($uid,$OnUserArray)){//有权限
            //执行减少硬币的炒作
            $this->DataModel->setOnUserStatus($roomid,$uid);
        }else{
            //提示客户没有权限
        }

    }

    //游戏中用户领奖方法  领取奖励后  用户处于 禁止投币状态  等待游戏大局重新开始
    public function award(){

    }

    //todo  对战方法
    /*接受  玩家发送的对战数据
     *存入玩家的数据
     * */
    public function war(){
        $uid=$this->SocketData['uid'];
        $roomid=$this->SocketData['roomid'];
        $gameData=$this->SocketData['gameData'];//客户发送到数据
        $gameType=$this->SocketData['gameType'];
        $Gameindex=$this->SocketData['Gameindex'];//当前到格子位置
        $index=$this->DataModel->getGameIndex($roomid);
        if($index==$Gameindex){
            $this->DataModel->setMyGameData($roomid,$uid);
        }else{
            $reData['m']='warning';
            $reData['msg']="当前状态错误";
            Gateway::sendToUid($uid,json_encode($reData));
        }
    }
    //用户推出房间的方法
    public function outgame(){
        $uid=$this->SocketData['uid'];
        $roomid=$this->SocketData['roomid'];
        $this->DataModel->setUserOutGame($uid,$roomid);
        $allUser=$this->DataModel->getAllUserData($roomid);//获取所有当前在房间内到用户
        $reData['m']='outGame';
        $reData['uid']=$uid;
        Gateway::sendToUid($allUser,json_encode($reData));

    }
    //todo 绑定登录数据
    public function login(){
        Gateway::bindUid($this->SocketData['client_id'],$this->SocketData['uid']);
    }
}
?>